"use server";

import { wrapAction } from "@/server/wrapper";
import loginUserService from "@/server/service/login-user-service";
import postsService from "@/server/service/post/post-service";
import AppError from "@/shared/app-error";
import { Post } from "@prisma/client";
import { headers } from "next/headers";

export async function getMyPostById(postId: string) {
  return await wrapAction(async (): Promise<Post | null> => {
    const me = await loginUserService.getFromHeaders(headers());
    if (!me) {
        throw AppError.unauthError();
    }
    return await postsService.getMyPostById({ postId, me });
  });
}
